﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace YTSK
{
    public partial class FrmTip : Form
    {
        public FrmTip()
        {
            InitializeComponent();
            this.Icon = Properties.Resources.Fly;
        }

        public void SetValue(Model.TipConfig tip)
        {
            if (tip.bHide)
            {
                if (this.Visible) { this.Visible = false; }
            }
            else
            {
                if (!this.Visible)
                { this.Visible = true; }
            }
            string tipmsg;
            if (tip.tipm != null && tip.tipm.Length > 0)
            { tipmsg = string.Format("【{0}】--{1}", tip.tipm, tip.tip); }
            else { tipmsg = tip.tip; }
            int icurval = tip.ival;
            if (tip.itotal > 0)
            {
                tipmsg += string.Format("({0}/{1})", tip.ival, tip.itotal);
                icurval = tip.ival * 100 / tip.itotal;
            }
            this.LabTip.Text = tipmsg;
            this.PBTip.Value = icurval;
        }

        public void SetValue(string msg)
        {
            var tip = new Model.TipConfig() { tip = msg };
            SetValue(tip);
        }

        private DateTime lastupdate = new DateTime(2000, 1, 1);
        public void setValue(string tipMemo, int iValue = 0, int iTotal = 0, int iStart = 0, int iLen = 0)
        {
            var ts = DateTime.Now - lastupdate;
            if (ts.TotalSeconds < 1)
            { return; }
            if (iTotal > 0)
            {
                tipMemo += "(" + iValue + "/" + iTotal + ")";
            }
            this.LabTip.Text = tipMemo;

            if (iTotal > 0)
            {
                int iCurValue = iStart + iValue * iLen / iTotal;
                if (iCurValue >= 0 && iCurValue <= 100)
                { this.PBTip.Value = iCurValue; }
            }
            else
            {
                if (iStart > 0 && iStart <= 100)
                {
                    this.PBTip.Value = iStart;
                }
                else
                { this.PBTip.Value = iValue; }
            }
            this.LabTip.Refresh();
            Application.DoEvents();
            lastupdate = DateTime.Now;
        }
    }
}
